package com.atguigu.servicebase.exceptionhandler;

import com.atguigu.commonutils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public R error(Exception e) {
        log.warn(e.getMessage());
        return R.error().data("exception", e.getMessage()).message("全局异常处理");
    }

    @ExceptionHandler(GuliException.class)
    public R error(GuliException e) {
        log.warn(e.getMsg());
        return R.error().code(e.getCode()).message(e.getMsg());
    }
}
